package Model.DAO;


import Model.Entity.Cpicture;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class CpictureDao extends BaseDao {

    public CpictureDao() {
        super("cpicture");
    }
    //新增图片
    public boolean insertCpicture(Cpicture cpicture)
    {
        cpicture.setId(EntityCount());
        return insert(cpicture);
    }
    //查询商品图片
    public String getFirstCpicurlByCommodityId(Long commodityid){
        try {
            Connection conn = dataSource.getConnection();
            PreparedStatement stm = conn.prepareStatement("SELECT  * FROM cpicture WHERE cid=?");
            stm.setLong(1,commodityid);
            ResultSet rst = stm.executeQuery();
            if (rst.next()){
                String res = rst.getString("picurl");
                conn.close();
                return res;
            }
            conn.close();
            return null;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
}
